package com.company.strs;

import java.util.ArrayList;
import java.util.List;

public class TranslateNum {
    public int translateNum(int num) {
        String str = num + "";
        List<String> result = new ArrayList<>();
        process(0,str,"",result);
        System.out.println(result);
        return result.size();
    }
    
    private String translate(String digitStr){
        switch (digitStr){
            case "0":return "a";
            case "1":return "b";
            case "2":return "c";
            case "3":return "d";
            case "4":return "e";
            case "5":return "f";
            case "6":return "g";
            case "7":return "h";
            case "8":return "i";
            case "9":return "j";
            case "10":return "k";
            case "11":return "l";
            case "12":return "m";
            case "13":return "n";
            case "14":return "o";
            case "15":return "p";
            case "16":return "q";
            case "17":return "r";
            case "18":return "s";
            case "19":return "t";
            case "20":return "u";
            case "21":return "v";
            case "22":return "w";
            case "23":return "x";
            case "24":return "y";
            case "25":return "z";
            default:return "";
        }
    }
    
    private void process(int curPosition, String str, String path, List<String> pathList) {
        if (curPosition == str.length()) {
            pathList.add(path);
            return;
        }
        //处理当前 字符
        char c = str.charAt(curPosition);
        //分为两种情况 
        //一、当做一位数 处理翻译

        process(curPosition+1,str,path+translate(c+""),pathList);
        //二、当做两位数处理 判断是否符合两位数的条件
        if (curPosition==str.length()-1) {//当前已经是最后一个要处理的数字
            return;
        }
        if (c !='1'&& c!='2') {
            return;
        }
        char next = str.charAt(curPosition+1);
        if (c =='1') {
            String translate = translate(c+"" + next);
            process(curPosition+2,str,path+translate,pathList);
            return;
        }
        if ((next >= '0'&&next<='5')) {
            String translate = translate(c + ""+next);
            process(curPosition+2,str,path+translate,pathList);
        }
    }
}
